﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace HR60_PanelSoft.Tools
{
	public class RefHelper
	{
		public static Dictionary<string, object> getProperties<T>(T t)
		{
			var res = new Dictionary<string, object>();
			if (t == null) { return null; }
			PropertyInfo[] properties = t.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
			foreach (PropertyInfo item in properties)
			{
				string name = item.Name;
				object value = item.GetValue(t, null);
				res.Add(name, value);
			}
			return res;
		}

		public static Dictionary<string, object> getFields<T>(T t)
		{
			var res = new Dictionary<string, object>();
			if (t == null) { return null; }
			FieldInfo[] fields = t.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public);
			foreach (FieldInfo item in fields)
			{
				string name = item.Name;
				object value = item.GetValue(t);
				res.Add(name, value);
			}
			return res;
		}
	}
}
